<template>
  <div class="row">
    <div v-for="column in columnList" :key="column.id" class="col-4 mb-4">
      <div class="card h-100 shadow-sm">
        <div class="card-body text-center">
          <img
            :src="column.avatarUrl"
            :alt="column.title"
            class="rounded-circle border border-light my-3"
          />
          <h5 class="card-title">{{ column.title }}</h5>
          <p class="card-text text-left">{{ column.description }}</p>
          <a href="#" class="btn btn-outline-primary">进入专栏</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { ColumnProps } from "@/store";
import { computed, defineComponent, PropType } from "vue";

export default defineComponent({
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true,
    },
  },
  setup(props) {
    const columnList = computed(() =>
      props.list.map((column) => ({
        ...column,
        avatarUrl: column.avatar
          ? column.avatar.url + "?x-oss-process=image/resize,m_pad,h_50,w_50"
          : "http://vue-maker.oss-cn-hangzhou.aliyuncs.com/vue-marker/5ee22dd58b3c4520912b9470.jpg",
      }))
    );
    return {
      columnList,
    };
  },
});
</script>
<style scoped>
.card-body img {
  width: 50px;
  height: 50px;
}
</style>
